package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.constant.NumConstants;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysMemberMapper;
import com.ruoyi.system.domain.SysMember;
import com.ruoyi.system.service.ISysMemberService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@Service
public class SysMemberServiceImpl implements ISysMemberService 
{
    @Autowired
    private SysMemberMapper sysMemberMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public SysMember selectSysMemberById(Long id)
    {
        return sysMemberMapper.selectSysMemberById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param sysMember 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<SysMember> selectSysMemberList(SysMember sysMember)
    {
        return sysMemberMapper.selectSysMemberList(sysMember);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param sysMember 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSysMember(SysMember sysMember)
    {
        //检查用户是否存在
        if (sysMember.getUserId() != null) {
            SysUser sysUser = sysUserMapper.selectUserById(sysMember.getUserId());
            if(sysUser.getUserName().equals(sysMember.getUserName())){
                SysMember member = sysMemberMapper.selectSysMemberByUserId(sysMember.getUserId());
                if (member == null){
                    return sysMemberMapper.insertSysMember(sysMember);
                }
            }
        }
        return NumConstants.ZERO;
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param sysMember 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSysMember(SysMember sysMember)
    {
        return sysMemberMapper.updateSysMember(sysMember);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysMemberByIds(Long[] ids)
    {
        return sysMemberMapper.deleteSysMemberByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysMemberById(Long id)
    {
        return sysMemberMapper.deleteSysMemberById(id);
    }

    @Override
    public SysMember selectSysMemberByUserId(Long userId) {
        return sysMemberMapper.selectSysMemberByUserId(userId);
    }

    @Override
    public SysMember selectSysMemberByUserName(String username) {

        return sysMemberMapper.selectSysMemberByUserName(username);
    }
}
